//
//  ViewController.m
//  Crash
//
//  Created by 周成龙 on 2019/5/7.
//  Copyright © 2019 周成龙. All rights reserved.
//

#import "ViewController.h"
#import "NextViewController.h"

typedef struct Test {
    int a;
    int b;
} Test;

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
}

- (IBAction)nextAction:(UIBarButtonItem *)sender {
//    dispatch_sync(dispatch_get_main_queue(), ^{ });
    
    NextViewController *vc = [[NextViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

- (IBAction)SignalExceptionBtnClick:(UIButton *)sender {
    Test *pTest = {1, 2};
    free(pTest);
    pTest->a = 5;
}

- (IBAction)OCExceptionBtnClick:(UIButton *)sender {
    NSArray *array= @[@"tom",@"xxx",@"ooo"];
    [array objectAtIndex:5];
}

- (IBAction)KVOCrash:(UIButton *)sender {
    NSMutableDictionary * dic = [@{@"name":@"小明"} mutableCopy];
    [dic setObject:nil forKey:@"gender"];
}

// 内存暴增，局部变量没有释放
- (IBAction)memoryCrash:(UIButton *)sender {
    NSMutableArray *arr = [NSMutableArray arrayWithCapacity:0];
    for (NSInteger i = 0; i < 5000000000000; i++) {
        NSString *obj = @"qwertyuiop";
        [arr addObject:obj];
    }
    
//    [[UIApplication sharedApplication] performSelector:@selector(_performMemoryWarning)];
    NSLog(@"----");
}

- (void)didReceiveMemoryWarning {
    NSLog(@"didReceiveMemoryWarning");
    
    [super didReceiveMemoryWarning];
}

@end
